<?php
/**
 * 
 * Application Page Controller
 * 
 * @category Abovo
 * 
 * @package Abovo
 * 
 * @author Antti Holvikari <anttih@gmail.com>
 * 
 * @license http://opensource.org/licenses/gpl-license.php GPL
 *
 */

/**
 *
 * Page controller
 *
 * @category Abovo
 * 
 * @package Abovo_Controller
 * 
 */
class Abovo_Controller_Page extends Solar_Controller_Page {
    
    /**
     * 
     * Points an existing Solar_View object to the Layout templates.
     * 
     * Automatically sets up a template-path stack for you, searching
     * for layout files in this order (different than Solar's default order)
     * 
     * 1. Vendor/App/Layout/
     * 
     * 2. Abovo/App/Layout/
     * 
     * @param Solar_View $view The Solar_View object to modify.
     * 
     * @return Solar_View
     * 
     */
    protected function _setViewLayout($view)
    {
        // get the current class
        $class = get_class($this);
        
        // get the parent-level class
        $pos = strrpos($class, '_');
        $parent = substr($class, 0, $pos);
        
        // who's the vendor?
        $pos = strpos($class, '_');
        $vendor = substr($class, 0, $pos);
        
        // reset template paths in the view object.
        // the order of searching will be:
        // Vendor/App/Layout, Abovo/App/Layout
        $template = array();
        
        // add 'Vendor' as the first in the stack
        $template[] = str_replace('_', DIRECTORY_SEPARATOR, "{$vendor}_App_Layout");
        
        if ($vendor != 'Abovo') {
            // add Abovo as the last in the stack
            $template[] = str_replace('_', DIRECTORY_SEPARATOR, "Abovo_App_Layout");
        }
        
        $view->setTemplatePath($template);
    }
}
